package com.example.v2.service;

import com.example.v2.model.dto.SpringbootDemoDTO;
import com.example.v2.model.entity.baoxian.SpringbootDemoEntity;
import com.example.v2.model.mapper.SpringbootDemoMapper;
import com.example.v2.repository.baoxian.SpringbootDemoRepository;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author DongXL
 * @Create 2017-12-22 14:06
 */

@Service
public class DemoService {


    @Resource
    private SpringbootDemoRepository springbootDemoRepository;

    @Cacheable(cacheNames = "demo", key = "#demoId+''")
    public SpringbootDemoDTO getSpringbootDemo(Long demoId) {
        SpringbootDemoEntity demoEntity = springbootDemoRepository.getOne(demoId);
        return SpringbootDemoMapper.INSTANCE.toDTO(demoEntity);
    }

    public List<SpringbootDemoDTO> getSpringbootDemoList() {
        List<SpringbootDemoEntity> demoEntityList = springbootDemoRepository.findAllByDeletedFalse();
        return SpringbootDemoMapper.INSTANCE.toDTO(demoEntityList);
    }


}
